package cn.zf233.xcloud.config;

import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.redis.spring.RedisLockProvider;
import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;

/**
 * Created by zf233 on 2021/6/1
 * ShedLock 配置类
 */
@Configuration
@EnableSchedulerLock(defaultLockAtMostFor = "PT55S")
@ConditionalOnBean(RedissonConfig.class)
public class ShedLockConfig {

    @Value("${spring.profiles.active}")
    private String env;

    // ShedLock
    @Bean
    public LockProvider lockProvider(RedisConnectionFactory factory) {
        return new RedisLockProvider(factory, env);
    }
}
